%include "exception.i"
%exception bb_dev_list_t {
  $action
  if (!result) {
    PyErr_SetString(PyExc_IOError, "no device");
    SWIG_fail;
  }
}

%ignore bb_dev_getlist(bb_dev_list_t **pButler,const char* addr,int port);
%ignore bb_dev_freelist(bb_dev_list_t *ppButler);
// Add in a custom proxy constructor and destructor
struct bb_dev_list_t {};
%extend bb_dev_list_t {
  bb_dev_list_t(bb_host_t* phost) {
    bb_dev_list_t *pButler = 0;
    int num = bb_dev_getlist(phost,&pButler);
    if(num >= 0) {
        listmap_add(pButler, num);
    }
    return (struct bb_dev_list_t *)pButler;
  }
  int get_num() {
    return listmap_get($self);
  }

  bb_dev_t* bb_dev_getlist_index(int index) {
    return bb_dev_getlist_index((bb_dev_list_t *)$self, index);
  }
  ~bb_dev_list_t() {
     listmap_del($self);
     bb_dev_freelist((bb_dev_list_t *)$self);
   }
}
